package com.mzy.basics.network;

import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author mzy
 * @Date 2022/5/18 14:53
 * @Version 1.0
 */
public class NetWork {
    /**
     * 获取操作系统上所有的网卡，不管是启用还是没启用（有真实物理地址的）
     * @param args
     * @throws SocketException
     */
    public static void main(String[] args) throws SocketException {
        Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
        while (networkInterfaces.hasMoreElements()) {
            NetworkInterface ni = networkInterfaces.nextElement();
            if (ni.isUp())
            continue;
            byte[] hardwareAddress = ni.getHardwareAddress();
            if (hardwareAddress != null) {
                System.out.println(ni);
                }
            }
        }
    }
